// screens/msg_list_screen.dart
import 'package:chat/controller/messageg_list_controller.dart';
import 'package:chat/generated/l10n.dart';
import 'package:chat/model/message_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';

final MessageListController messageListController = Get.find();

class MessageListScreen extends StatelessWidget {
  const MessageListScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        elevation: 0,
        leading: const Padding(
          padding: EdgeInsets.only(left: 16.0, top: 10.0),
          child: Text(
            '聊天',
            style: TextStyle(
              fontSize: 20,
              fontWeight: FontWeight.bold,
              color: Colors.black,
            ),
          ),
        ),
        leadingWidth: 100,
        actions: [
          IconButton(
            icon: Image.asset(
              'assets/images/friend_album.jpg', // 你的图片路径
              width: 34, // 调整大小
              height: 34,
            ),
            onPressed: () {
              Get.toNamed('/friendListScreen');
            },
          ),
          IconButton(
            icon: Image.asset(
              'assets/images/add_group.jpg', // 你的图片路径
              width: 34, // 调整大小
              height: 34,
            ),
            onPressed: () {
              Get.toNamed('/friendListScreen');
            },
          ),
        ],
      ),
      body: Stack(
        children: [
          // 背景图层
          Positioned.fill(
            child: Image.asset(
              'assets/images/dl_bj_img.webp',
              fit: BoxFit.cover, // 覆盖全屏
            ),
          ),
          Column(
            children: [
              // Padding(
              //   padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
              //   child: TextField(
              //     decoration: InputDecoration(
              //       hintText: '搜索好友',
              //       prefixIcon: const Icon(Icons.search),
              //       border: OutlineInputBorder(borderRadius: BorderRadius.circular(10.0), borderSide: BorderSide.none),
              //       filled: true,
              //       fillColor: Colors.grey[200],
              //       contentPadding: const EdgeInsets.symmetric(vertical: 0),
              //     ),
              //     onChanged: (value) => messageListController.searchQuery.value = value,
              //   ),
              // ),
              Center(
                child: GestureDetector(
                  onTap: () {
                    // 获取当前语言
                    final currentLocale = Get.locale ?? const Locale('zh');

                    // 切换语言（示例：中英文切换）
                    if (currentLocale.languageCode == 'zh') {
                      Get.updateLocale(const Locale('en'));
                    } else {
                      Get.updateLocale(const Locale('zh'));
                    }
                  },
                  child: Stack(
                    alignment: AlignmentDirectional.center,
                    children: [
                      SizedBox(child: SvgPicture.asset('assets/images/Rectangle4112.svg')),
                      Text(
                        S.of(context).hello,
                        style: TextStyle(color: Colors.black),
                      ),
                    ],
                  ),
                ),
              ),
              SizedBox(height: 10),
              // Center(
              //   child: Stack(
              //     alignment: AlignmentDirectional.center,
              //     children: [
              //       SizedBox(
              //           width: 200,
              //           child: SvgPicture.asset(
              //             'assets/images/Rectangle4112.svg',
              //             fit: BoxFit.fill,
              //           )),
              //       Text(
              //         '登陆',
              //         style: TextStyle(color: Colors.black),
              //       ),
              //     ],
              //   ),
              // ),
              SizedBox(height: 10),
              Center(
                child: Stack(
                  alignment: AlignmentDirectional.center,
                  children: [
                    SizedBox(
                        width: 100,
                        height: 60,
                        child: SvgPicture.asset(
                          'assets/images/Rectangle4112.svg',
                          fit: BoxFit.fill,
                        )),
                    Text(
                      '登陆',
                      style: TextStyle(color: Colors.black),
                    ),
                  ],
                ),
              ),
              Image.asset('assets/images/setting_map_icon.webp'),
              Image.asset('assets/images/pph5_xz_btn.webp'),
              // Center(
              //   child: Stack(
              //     alignment: AlignmentDirectional.center,
              //     children: [
              //       SizedBox(
              //         child: VectorGraphic(
              //           loader: AssetBytesLoader('assets/images/Rectangle4112.svg'),
              //         ),
              //       ),
              //       Text(
              //         '登陆',
              //         style: TextStyle(color: Colors.black),
              //       ),
              //     ],
              //   ),
              // ),
              // Expanded(
              //   child: Obx(
              //     () => ListView.builder(
              //       itemCount: messageListController.filteredMessages.length,
              //       itemBuilder: (context, index) {
              //         final message = messageListController.filteredMessages[index];
              //         return _messageItem(message);
              //       },
              //     ),
              //   ),
              // ),
            ],
          ),
        ],
      ),
    );
  }
}

Widget _messageItem(Message message) {
  return ListTile(
    leading: CircleAvatar(
      backgroundImage: AssetImage(message.senderAvatar),
      backgroundColor: Colors.grey[300],
    ),
    title: Text(
      message.senderName,
      style: TextStyle(fontWeight: FontWeight.bold),
    ),
    subtitle: Text(
      message.content,
      maxLines: 1,
      overflow: TextOverflow.ellipsis,
    ),
    trailing: Text(
      message.timeAgo,
      style: const TextStyle(fontSize: 12, color: Colors.grey),
    ),
    onTap: () {
      // 点击消息进入聊天详情
    },
  );
}
